<template>
	<view>
		<view class="search">
			<search :disabled="true" type="sell"></search>
		</view>
		<view class="list">
			<block v-for="item in sellList" :key="item.id">
				<sell-item :item="item"></sell-item>
			</block>
			
			<!--正在加载 start-->
			<v-loadmore :visible="load"></v-loadmore>
			<!--正在加载 end-->
			
			<!--没有更多了 start-->
			<v-nomore :visible="!load && isMore"></v-nomore>
		</view>
		
		<loading v-if="loading"></loading>
		
		<view class="bottom_shadow"></view>
	</view>
</template>

<script>
	import Search from "@/components/Search.vue"
	import SellItem from "@/components/SellItem.vue"
	import vNomore from "@/components/load/nomore.vue"
	import vLoadmore from "@/components/load/loadmore.vue"
	import TabModule from '@/Api/Tab.js'
	
	export default {
		components: {
			Search,
			SellItem,
			vNomore,
			vLoadmore
		},
		data() {
			return {
				loading: true,
				current_page: 0,
				isMore: false,
				load: true,
				sellList: []
			};
		},
		computed: {
			userInfo() {
				return this.$store.state.userInfo;
			}
		},
		onLoad() {
			this.getSellTicketList()
		},
		// 下拉回调方法
		onPullDownRefresh() {
			this.current_page = 0
			this.isMore = false
			this.load = true
			this.getSellTicketList()
		},
		// 上拉回调方法
		onReachBottom() {
			if(!this.isMore) {
				this.getSellTicketList()
			}
		},
		methods: {
			getSellTicketList() {
				this.load = true
				let { current_page, sellList } = this
				TabModule.getSellTicketList(current_page)
					.then((res)=>{
						if(current_page == 0) sellList = []
						 let onMore = false
						 let len = res.data.length
						 len > 0 ? res.data.forEach(item =>  sellList.push(item)) :  onMore = true
						this.sellList = sellList
						this.load = false
						this.current_page = res.current_page
						this.isMore = len < res.per_page ? true: false
						this.onMore = onMore
						this.loading = false
						// 停止页面刷新
						uni.stopPullDownRefresh()
					})
			}
		},
		onShareAppMessage() {
			let { nickName, id } = this.userInfo
			return {
				title: `${nickName}发现了一个好东西跟你分享`,
				path: id ? `/pages/Tab/BuyTicket/BuyTicket?userid=${id}` : '/pages/Tab/BuyTicket/BuyTicket',
				imageUrl: '/static/share.png'
			}
		}
	}
</script>

<style lang="scss">
	page{
		background-color: #fff;
	}
	.search{
		height: 100upx;
		width: 100%;
		box-sizing: border-box;
		background-color: #fff;
		position: fixed;
		top: 0;
		left: 0;
		right: 0;
		z-index: 100;
	}
	.list{
		margin-top: 130upx;
		padding-bottom: 30upx;
	}
</style>
